<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<script type="text/javascript">
function movePage(pageNo) {
	$.get("myMsgList.do?pageNo=" + pageNo + param() + '&' + Math.random(),
			function(data) {
				$("#main").html(data);
			});
}
function del(id) {
$.get("deleteMsg.do?id="+id,function(data){
			var o = jQuery.parseJSON(data);
					if(o.success){
						movePage(${param.pageNo});
						alert('操作成功！');
					}
					else
						alert('操作失败！'+o.err);
		});
	}
	function param() {
		var param = "";
		if ($("#classCode").val() != "")
			param += '&classCode=' + $("#classCode").val();
		if ($("#title").val() != "")
			param += '&title=' + $("#title").val();
		if ($("#description").val() != "")
			param += '&description=' + $("#description").val();
		return param;
	}
	$(document).ready(function() {
		$.get("getSelect.do", {
			type : 'ms',
			index : '${param.classCode}',
			code : null
		}, function(data) {
			$("select#classCode").append(data);
		});
		$("#search").button().click(function() {
			movePage(1);
		});
		$("#add").button().click(function() {
			$.get("msgForm.do?&"+Math.random(), function(data) {
				$("#main").html(data);
			});
		});
	});
	function edit(id){
		$.get("msgForm.do?&id="+id+"&"+Math.random(), function(data) {
				$("#main").html(data);
			});
	}
</script>



<table class="list" cellpadding="0" width="100%" cellspacing="1">
	<thead>
		<tr>
			<td class="search" colspan="4">
				<label>
					类别：
				</label>
				<select id="classCode">
					<option value="">
						不限制
					</option>
				</select>
				<label>
					标题：
				</label>
				<input type="text" name="title" id="title" value="${param.title }" />
				<label>
					内容：
				</label>
				<input type="text" name="description" id="description"
					value="${param.description }" />
				<button id="search">
					查询
				</button>
				<button id="add">
					发布
				</button>
			</td>
		</tr>
		<tr>
			<td>
				分类
			</td>
			<td>
				名称
			</td>
			<td>
				时间
			</td>
			<td>
				操作
			</td>
		</tr>
	</thead>
	<tbody>
		<c:forEach var="e" items="${o.dataList}" varStatus="s">
			<tr>
				<td>
					${e.className}
				</td>
				<td>
					<a href="showMsg.do?id=${e.id}" target="_blank">${e.title }</a>
				</td>
				<td align="center"><fmt:formatDate value="${e.inputdate}" pattern="yyyy/MM/dd" />
				</td>
				<td align="center"><a href="javascript:edit(${e.id})"><img src="lib/images/write.png"/></a>
					<a href="javascript:if(confirm('确定删除？'))del('${e.id}')"><img src="lib/images/close.gif"/></a>
				</td>
			</tr>
		</c:forEach>
	</tbody>
	<tfoot>
		<tr>
			<td colspan="4">
				${o.pageNav }
			</td>
		</tr>
	</tfoot>
</table>
